<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-02 19:42:06
 * @LastEditTime: 2023-10-03 16:07:54
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Repositories;

use App\Models\Company;

class CompanyRepository extends Repositories
    {

    protected $relation_models = ['creator', 'updator', 'link_mans', 'salesman', 'status', 'employee',  'billtrade', 'deptcust','category'];
    public function boot(Company $model)
        {
        $this->model = $model;
        }

    public function list()
        {
        return $this->model->get();
        }

    public function fuzzySearch($value)
        {
        $value = trim($value);
        $this->where(function ($query) use ($value)
            {
            $query->orWhere("name", "like", "%{$value}%");
            $query->orWhere("code", "like", "%{$value}%");
            });
        }
    public function delete($ids)
        {
        return $this->whereIn("id", $ids)->get()->filter(function ($v)
            {
            return $v->delete();
            });
        }
    }